package com.ybbase.framework.config.activiti;

import com.ybbase.framework.config.activiti.custom.groups.CustomGroupEntityManagerFactory;
import com.ybbase.framework.config.activiti.custom.user.CustomUserEntityManagerFactory;
import org.activiti.engine.impl.interceptor.SessionFactory;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author cg
 * @date 2019-08-22 15:15
 * @DEC
 */
@Configuration
public class ActivitiConfiguration implements ProcessEngineConfigurationConfigurer {

    @Autowired
    private CustomUserEntityManagerFactory customUserEntityManagerFactory;
    @Autowired
    private CustomGroupEntityManagerFactory customGroupEntityManagerFactory;
    @Override
    public void configure(SpringProcessEngineConfiguration springProcessEngineConfiguration) {
        //已验证-图片不会出现中文乱码
        springProcessEngineConfiguration.setActivityFontName("宋体");
        springProcessEngineConfiguration.setLabelFontName("宋体");
        springProcessEngineConfiguration.setAnnotationFontName("宋体");
        //自定义用户和组
        springProcessEngineConfiguration.setDbIdentityUsed(false);
        List<SessionFactory> customSessionFactories = new ArrayList<>();
        customSessionFactories.add(customUserEntityManagerFactory);
        customSessionFactories.add(customGroupEntityManagerFactory);
        springProcessEngineConfiguration.setCustomSessionFactories(customSessionFactories);
        //配置Activiti数据源
        springProcessEngineConfiguration.setDatabaseType("mysql");
    }
}
